package cn.ac.ict.fpevaluation.fastdtw.util;

import cn.ac.ict.fpevaluation.bean.APBean;

import java.util.List;

public class CosineDistance implements DistanceFunction {
    public CosineDistance() {

    }

    public double calcDistance(double[] vector1, double[] vector2) {
        if (vector1.length != vector2.length)
            throw new InternalError("ERROR:  cannot calculate the distance "
                    + "between vectors of different sizes.");


        double sumTop = 0;
        double sumOne = 0;
        double sumTwo = 0;


        for (int i = 0; i < vector1.length; i++) {
            sumTop += vector1[i] * vector2[i];
            sumOne += vector1[i] * vector1[i];
            sumTwo += vector2[i] * vector2[i];
        }
        double cosSim = sumTop / (Math.sqrt(sumOne) * Math.sqrt(sumTwo));
        if (cosSim < 0)
            cosSim = 0;//This should not happen, but does because of rounding errorsl
        return cosSim;

    }  // end class euclideanDist(..)


    public double calcDistance(List<APBean> list1, List<APBean> list2) {
        return 0;
    }

}
